﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using ENT.GP.Core;
using ENT.GP.Core.Core;
using entgp.Code;
using System.Xml;
using System.Text;

public partial class Tareas_Tareas : PaginasUsuario
{
    private ENT.GP.Core.Tareas.TareaLista TestData
    {
        get
        {
            int idUsuario, idRol;
            int.TryParse(Session["IdRol"].ToString(), out idUsuario);
            int.TryParse(Session["IdRol"].ToString(), out idRol);
            var criterioNot = ENT.GP.Core.Tareas.TareaCriterio.NewEditableRoot();
            //criterioNot.IdUsuario = 1;
            criterioNot.IdUsuario = 3;
            var listaNotificaciones = ENT.GP.Core.Tareas.TareaLista.GetTareaList(criterioNot);
            return (listaNotificaciones);
        
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {


                sTareas.DataSource = this.TestData;
                sTareas.DataBind();

            }
        }
        catch (Exception ex)
        {
            Util.RegistarLog(ex);
        }
        
    }

    protected void btnNuevo_click(object sender, DirectEventArgs e)
    {
        try
        {
            //wucPerfiles1.Show(e.ExtraParams["operacion"].ToString());
            wListadoTareas.Show();
        }
        catch (Exception)
        {

            throw;
        }
    }
    protected void btnBuscar_Click(object sender, DirectEventArgs e)
    {
        try
        {
            UtilP.MostrarNotificacion("El elemento no se activo/desactivo", "Aviso", MessageBox.Icon.ERROR);
        }
        catch { }
    }

    protected void MyData_Refresh(object sender, StoreRefreshDataEventArgs e)
    {
        this.sTareas.DataSource = this.TestData;
        this.sTareas.DataBind();
       
       
    }

  

    protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        XmlNode xml = e.Xml;

        this.Response.Clear();

        string strXml = xml.OuterXml;

        this.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xml");
        this.Response.AddHeader("Content-Length", strXml.Length.ToString());
        this.Response.ContentType = "application/xml";
        this.Response.Write(strXml);

        this.Response.End();
    }
   
    protected void SaveHandler(object sender, BeforeStoreChangedEventArgs e)
    {
        XmlNode xml = e.DataHandler.XmlData;
        StringBuilder sb = new StringBuilder();

        XmlNode updated = xml.SelectSingleNode("records/Updated");

      

        if (updated != null)
        {
            sb.Append("<p>Updated:</p>");

            XmlNodeList uRecords = updated.SelectNodes("record");

            foreach (XmlNode record in uRecords)
            {
                sb.Append("<p>").Append(Server.HtmlEncode(record.InnerXml)).Append("</p>");
            }

            sb.Append("<br/>");
        }

        XmlNode inserted = xml.SelectSingleNode("records/Created");

        if (inserted != null)
        {
            sb.Append("<p>Created:</p>");

            XmlNodeList iRecords = inserted.SelectNodes("record");

            foreach (XmlNode record in iRecords)
            {
                sb.Append("<p>").Append(Server.HtmlEncode(record.InnerXml)).Append("</p>");
            }

            sb.Append("<br/>");
        }

        XmlNode deleted = xml.SelectSingleNode("records/Deleted");

        if (deleted != null)
        {
            sb.Append("<p>Deleted:</p>");

            XmlNodeList dRecords = deleted.SelectNodes("record");

            foreach (XmlNode record in dRecords)
            {
                var id = record.FirstChild.InnerText;

                sb.Append("<p>").Append(Server.HtmlEncode(record.InnerXml)).Append("</p>");
            }

            sb.Append("<br/>");

            //this.gpPerfilProyecto.DeleteSelected();
            //#{gpPerfilProyecto}.deleteSelected();
        }

        //this.Label1.Html = sb.ToString();
        e.Cancel = true;

    }


    

}
